package com.example.mongodb_demo.controller;

import com.example.mongodb_demo.doman.Dish;
import com.example.mongodb_demo.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author aguang
 */
@RestController
public class DishController {

    @Resource
    private DishService dishService;

    @RequestMapping(value = "/addDish", method = {RequestMethod.GET, RequestMethod.POST})
    public String addDish(@RequestBody Dish dish) {
        Dish savedDish = dishService.addDish(dish);
        return "Dish added: " + savedDish.toString();
    }

    @GetMapping("/dish")
    public List<Dish> getDish() {
        return dishService.findDishAll();
    }
}
